package com.warom.sdg.dto;

import com.google.gson.annotations.SerializedName;
import java.util.List;

/**
 * 分页响应数据传输对象
 * 用于后端向前端返回分页数据
 * @param <T> 数据项类型
 */
public class PageResponseDto<T> {
    /**
     * 当前页码
     */
    @SerializedName("page")
    private int page;

    /**
     * 每页记录数
     */
    @SerializedName("pageSize")
    private int pageSize;

    /**
     * 总记录数
     */
    @SerializedName("totalCount")
    private long totalCount;

    /**
     * 总页数
     */
    @SerializedName("totalPages")
    private int totalPages;

    /**
     * 是否有上一页
     */
    @SerializedName("hasPrevious")
    private boolean hasPrevious;

    /**
     * 是否有下一页
     */
    @SerializedName("hasNext")
    private boolean hasNext;

    /**
     * 数据列表
     */
    @SerializedName("list")
    private List<T> list;

    // 构造函数
    public PageResponseDto() {
    }

    public PageResponseDto(int page, int pageSize, long totalCount, List<T> list) {
        this.page = page;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.list = list;
        
        // 计算总页数
        this.totalPages = pageSize > 0 ? (int) Math.ceil((double) totalCount / pageSize) : 0;
        
        // 计算是否有上一页和下一页
        this.hasPrevious = page > 1;
        this.hasNext = page < totalPages;
    }

    // Getters and Setters
    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public boolean isHasPrevious() {
        return hasPrevious;
    }

    public void setHasPrevious(boolean hasPrevious) {
        this.hasPrevious = hasPrevious;
    }

    public boolean isHasNext() {
        return hasNext;
    }

    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
} 